package com.shuke.medical.insure.billDownload;

import com.shuke.medical.insure.billDownload.DBUtil;
import com.shuke.medical.insure.billDownload.WXPayBill;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;

/***
 * @title WXPayBillDBUtil
 * @description：创建写入数据到数据库的工具类
 * @author woo hua
 * @version 1.0.0
 * @create 2023/4/13 14:55
 **/
public class WXPayBillDBUtil {

    public static void insertWXPayBills(List<WXPayBill> bills) throws SQLException {
        Connection connection = null;
        PreparedStatement statement = null;

        try {
            connection = DBUtil.getConnection();
            String sql = "insert into wx_pay_bill(trade_time, appid, mch_id, sub_mch_id, device_info, " +
                    "transaction_id, out_trade_no, openid, trade_type, trade_status, bank_type, fee_type, " +
                    "total_fee, coupon_fee, refund_id, out_refund_no, refund_fee, refund_coupen_fee, " +
                    "refund_type, refund_status, body, attach, fee_description, account_type) " +
                    "values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
            statement = connection.prepareStatement(sql);

            for (WXPayBill bill : bills) {
                statement.setString(1, bill.getTradeTime());
                statement.setString(2, bill.getAppid());
                statement.setString(3, bill.getMchId());
                statement.setString(4, bill.getSubMchId());
                statement.setString(5, bill.getDeviceInfo());
                statement.setString(6, bill.getTransactionId());
                statement.setString(7, bill.getOutTradeNo());
                statement.setString(8, bill.getOpenId());
                statement.setString(9, bill.getTradeType());
                statement.setString(10, bill.getTradeStatus());
                statement.setString(11, bill.getBankType());
                statement.setString(12, bill.getFeeType());
                statement.setString(13, bill.getTotalFee());
                statement.setString(14, bill.getCouponFee());
                statement.setString(15, bill.getRefundId());
                statement.setString(16, bill.getOutRefundNo());
                statement.setString(17, bill.getRefundFee());
                statement.setString(18, bill.getRefundCoupenFee());
                statement.setString(19, bill.getRefundType());
                statement.setString(20, bill.getRefundStatus());
                statement.setString(21, bill.getBody());
                statement.setString(22, bill.getAttach());
                statement.setString(23, bill.getFeeDescription());
                statement.setString(24, bill.getAccountType());
                statement.addBatch();
            }

            statement.executeBatch();
        } finally {
            DBUtil.close(null, statement, connection);
        }
    }
}
